# SPDX-License-Identifier: GPL-3.0-only
#
# Copyright (C) 2021 ImmortalWrt.org

include $(TOPDIR)/rules.mk

PKG_NAME:=pydio_lede
PKG_VERSION:=4.4.8
PKG_RELEASE:=1

PKG_SOURCE_NAME:=cloudreve-master
PKG_SOURCE_PROTO:=git
PKG_SOURCE_URL:=https://github.com/pydio/cells.git
#PKG_SOURCE_DATE:=2025-01-14
PKG_SOURCE_VERSION:=7f162924042ce95a4ee627ce94d0e32ad0ac3732
PKG_MIRROR_HASH:=skip

PKG_LICENSE:=GPL-3.0-only
PKG_LICENSE_FILES:=LICENSE
PKG_MAINTAINER:=JoyNine<joyplayer@126.com>

PKG_BUILD_DEPENDS:=golang/host node/host node-yarn/host
PKG_BUILD_PARALLEL:=1
PKG_BUILD_FLAGS:=no-mips16

PKG_BUILD_DEPENDS:=mariadb_lede/host

GO_PKG:=github.com/pydio/cells/v4
GO_PKG_INSTALL_ALL:=1
GO_PKG_LDFLAGS_X:= $(GO_PKG)/common.version=${PKG_VERSION} \
	 $(GO_PKG)/common.BuildStamp=${TODAY} \
	 $(GO_PKG)/common.BuildRevision=${PKG_VERSION}
GO_PKG_BUILD_PKG:=$(GO_PKG)

include $(INCLUDE_DIR)/package.mk
include $(TOPDIR)/feeds/packages/lang/golang/golang-package.mk

MAKE_VARS = \
      CC="$(TARGET_CC)" \
      CFLAGS="$(TARGET_CFLAGS)" \
      LDFLAGS="$(TARGET_LDFLAGS)"
      
define Package/pydio_lede
  SECTION:=net
  CATEGORY:=Network
  SUBMENU:=Cloud Manager
  TITLE:=(LEDE) A project helps you build your own cloud in minutes
  URL:=https://cloudreve.org
  DEPENDS:=$(GO_ARCH_DEPENDS) +libc +ca-bundle +mariadb_lede-server-base +mariadb_lede-server
endef

define Package/pydio_lede/description
  Self-deployed file management and sharing system, supports multiple
  storage providers.
endef

define Package/pydio_lede/config
  config DOCKER_COMPOSE_LEDE_COMPRESS_GOPROXY
	bool "Compiling with GOPROXY proxy"
	default y
endef

ifeq ($(CONFIG_DOCKER_COMPOSE_LEDE_COMPRESS_GOPROXY),y)
export GO111MODULE=on
export GOPROXY=https://goproxy.cn,direct
endif

define Build/Compile
	( \
		pushd $(PKG_BUILD_DIR) ; \
		cd cmd/cells-fuse ; \
		make main ; \
		popd ; \
		$(call GoPackage/Build/Compile) ; \
	)
endef

define Package/pydio_lede/install
	$(INSTALL_DIR) $(1)/usr/bin
	$(INSTALL_BIN) $(GO_PKG_BUILD_BIN_DIR)/cells $(1)/usr/bin/cells
	$(INSTALL_BIN) $(PKG_BUILD_DIR)/cmd/cells-fuse/cells-fuse $(1)/usr/bin/cells-fuse
	
	$(INSTALL_DIR) $(1)/etc/config
	$(INSTALL_DATA) ./files/cells.config $(1)/etc/config/cells
	
	$(INSTALL_DIR) $(1)/etc/init.d
	$(INSTALL_DATA) ./files/cells.init $(1)/etc/init.d/cells
endef

define Package/pydio_lede/conffiles
/etc/config/cells
endef

define Package/pydio_lede/postinst
#!/bin/sh
[ -n "$$IPKG_INSTROOT" ] || {
	/etc/init.d/cells enable
	/etc/init.d/cells uciadd
	/etc/init.d/cells start
}
endef

define Package/pydio_lede/prerm
#!/bin/sh
[ -n "$$IPKG_INSTROOT" ] || {
	/etc/init.d/cells disable
	/etc/init.d/cells stop
	/etc/init.d/cells ucidel
}
endef

$(eval $(call GoBinPackage,pydio_lede))
$(eval $(call BuildPackage,pydio_lede))
